package dao;

import org.hibernate.Query;
import org.hibernate.Session;

import dominio.RemitoProveedor;

public class RemitoProveedorDAO {
	private static String query_buscarRemitoProveedor = "from RemitoProveedor r where r.id = (:id)";

	private static RemitoProveedorDAO instancia = null;

	public static RemitoProveedorDAO getInstance() {
		if (instancia == null)
			instancia = new RemitoProveedorDAO();
		return instancia;
	}

	private RemitoProveedorDAO() {}

	public int guardarRemitoProveedor(RemitoProveedor rp) {
		Session s = HibernateDAO.getInstance().getSession();
		s.beginTransaction();
		s.saveOrUpdate(rp);
		s.getTransaction().commit();
		return rp.getId();
	}

	public RemitoProveedor buscarRemitoProveedor(int id) {
		Session s = HibernateDAO.getInstance().getSession();
		Query query = s.createQuery(query_buscarRemitoProveedor);
		query.setParameter("id", id);
		query.setMaxResults(1);
		return (RemitoProveedor) query.uniqueResult();
	}
}